package main

import (
	"fmt"
	"math/rand"
)

func MultiplicationTable() {
	for i := 1; i < 10; i++ {
		for j := 1; j <= i; j++ {
			if i*j > 9 {
				fmt.Printf("%d*%d=%d  ", j, i, i*j)
			} else {
				fmt.Printf("%d*%d=%d   ", j, i, i*j)
			}
		}
		fmt.Println()
	}
}
func OddSumAndEvenProduct(length int) (int, int) {
	s := make([]int, 0, length*5) //如果是make([]int, length, length*5)将从length+1开始追加，前面length个长度值全是0,len(s)将为40
	var random int
	var sum, product int = 0, 1
	for i := 0; i <= length; i++ {
		random = rand.Intn(100)
		if rand.Intn(100) <= 0 {
			continue
		}
		s = append(s, random)
	}
	fmt.Println(s)
	for j, e := range s {
		if (j+1)%2 == 1 {
			sum += e
		}
		if (j+1)%2 == 0 {
			product *= e
		}
	}
	return sum, product
}
func Fibonacci() {
	var arr = [100]int{0, 1}      //数组给定前两个元素值是为了保证循环中arr[i] = arr[i-2] + arr[i-1]不为0
	var slice []int = []int{0, 1} //循环从数组第三个位置开始，切片前两个元素要占上
	for i := 2; i < 100; i++ {
		arr[i] = arr[i-2] + arr[i-1]
		if arr[i] > 100 {
			fmt.Println(i)
			goto Label
		}
		slice = append(slice, arr[i])
	}
Label:
	fmt.Println(slice)
}
func Fibona() {
	s := make([]int, 0)
	s = append(s, 0, 1)
	var (
		i int
		e int
	)
	for i = 0; i < 14; i++ {
		e = s[i] + s[i+1]
		if e > 100 {
			break
		}
		s = append(s, e)
	}
	fmt.Println(s)
}
func Fbi(i int) int {
	if i < 2 {
		if i == 1 {
			return 1
		}
		if i == 0 {
			return 0
		}
	}
	return Fbi(i-2) + Fbi(i-1)
}
func main() {
	MultiplicationTable()
	fmt.Println("-----------------------------------------------------------------------------------------------------")
	sum, product := OddSumAndEvenProduct(20)
	fmt.Printf("第单数个值累加求和为：%d，第双数个累乘求积为：%d\n", sum, product)
	fmt.Println("==============================================================")
	Fibonacci()
	for i := 0; i < 12; i++ {
		fmt.Printf("%d\n", Fbi(i))
	}
	fmt.Println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
	Fibona()
}
